<template>
	<view class="container-warp">
		<view class="p20">
			<view class="search-box">
				<image src="../../static/logs/search-icon.png" mode="" @click="init"></image>
				<u-input v-model="searchValue" placeholder='输入客户、网点、创建人名称' type="text" @input='init' />
			</view>
		</view>

		<!-- <scroll-view  scroll-x="true"> -->
		<view class="search-tab">
			<view class="select-tab" v-for="(item,index) in selectTabList">
				<view class="tab-item" @click="tabSearch(index,item)" :class="tabIndex==index?'active':''">
					{{item.label}}
					<view class="search-tab-line" :class="tabIndex==index?'lineActive':''"></view>
				</view>
			</view>
		</view>

		<!-- </scroll-view> -->
		<view class="p20">
			<view class="search-radio">
				<u-radio-group v-model="radio">
					<u-radio @change="checkboxGroupChange" v-for="(item, index) in list" :key="index"
						:name="item.value">{{item.name}}</u-radio>
				</u-radio-group>
			</view>

			<scroll-view scroll-y="true" class="scroll-list" @scrolltolower="scrolltolower">
				<view>
					<view class="list-item" v-for="item in dataList" :key="item.id"  @click="editCostomer(item)">
						<view class="header-box p30">
							<view class="title-box">
								<text class="title-name">{{item.logCode}}</text>
							</view>
							<view class="list-state">

								<!-- <text>新建</text> -->
								<text class="state1" v-if="item.isApprove==0" style="color: #ccc;">未批示</text>
								<text class="state1" v-if="item.isApprove==1">已批示</text>
								<text class="state-line" >｜</text>
								<text v-if="item.status==0">新建</text>
								<text class="state2" v-if="item.status==1">提交</text>
							</view>
						</view>
						<view class="list-line">

						</view>
						<view class="content-box p30">
							<view class="info-item">
								<text class="info-label">选商名称</text> <text>：</text> <text
									class="info-value">{{item.customerName}}</text>
							</view>
							<view class="info-item">
								<text class="info-label">网点名称</text> <text>：</text> <text
									class="info-value">{{item.marketName}}</text>
							</view>
							<view class="info-item">
								<text class="info-label">洽谈进度</text><text>：</text>
								<text class="info-value" v-for="i in progressList" :key="i.dictValue"
									v-if="item.talkProgress==i.dictValue">{{i.dictLabel}}</text>
							</view>
							<view class="info-item">
								<text class="info-label">创 建 人</text><text>：</text> <text
									class="info-value">{{item.custName}}</text>
							</view>
							<view class="info-item">
								<text class="info-label">创建时间</text><text>：</text> <text
									class="info-value">{{item.createTime.slice(0,10)}}</text>
							</view>
						</view>
						<view class="look-log-wrap p30" v-if="item.status==1">
							<view class="look-log" @click.stop="godetail(item)">
								批示
							</view>
						</view>

					</view>
				</view>
			</scroll-view>


		</view>
		<view class="add-btn-wrap">
			<view class="add-btn" @click="newAdd">
				新建
			</view>
		</view>
	</view>
</template>

<script>
	import {
		followupList,
		followupCount,
		getSystemDictData
	} from '@/common/service.js'
	export default {
		data() {
			return {
				searchValue: '',
				selectTabList: [{
						label: '全部',
						value: '',
					}, {
						label: '新建',
						value: '0',
					}, {
						label: '提交',
						value: '1',
					}, {
						label: '未批示',
						value: '2',
					}, {
						label: '已批示',
						value: '3',
					},

				],
				dataList: [],
				tabIndex: 0,
				list: [{
						name: '看自己',
						value: this.CONFIG.user.id,
					},
					{
						name: '看全部',
						value: '',
					},

				],
				progressList: [],
				pageNum: 1,
				pageSize: 10,
				status: '',
				radio: this.CONFIG.user.id
			};
		},
		onLoad() {
			this.getDictList()
			this.getNumList()
			this.getList()
			uni.$on('getList', () => {
				this.radio = this.CONFIG.user.id
				this.status = ''
				this.searchValue = ''
				this.init()
			})
		},
		methods: {
			getDictList() {
				let data = 'negotiation_progress'
				getSystemDictData(data,
					(res) => {
						this.progressList = res.data.data

					}, (e) => {
						this.$refs.uToast.show({
							title: e,
							type: "error",
							duration: 3000,
						});
					}
				)
			},
			init() {
				this.dataList = []
				this.pageNum = 1
				this.pageSize = 10
				this.getNumList()
				this.getList()
			},
			search() {
				this.init()
			},
			checkboxGroupChange(e) {
				this.init()
			},
			scrolltolower() {
				this.pageNum++
				this.getList()
			},
			getNumList() {
				let data = {
					keyWord: this.searchValue,
					custId: this.radio,
				}
				followupCount(data,
					(res) => {
						console.log(res, 9999999);
						let data = res.data.data
						this.selectTabList[0].label = `全部(${data.allCount})`
						this.selectTabList[1].label = `新建(${data.newCount})`
						this.selectTabList[2].label = `提交(${data.submitCount})`
						this.selectTabList[3].label = `未批示(${data.notApprovedCount})`
						this.selectTabList[4].label = `已批示(${data.approvedCount})`
					}, (e) => {
						this.$refs.uToast.show({
							title: e,
							type: "error",
							duration: 3000,
						});
					}
				)
			},
			getList() {
				let data = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					keyWord: this.searchValue,
					custId: this.radio,
					status: this.status
				}
				followupList(data,
					(res) => {
						let list = res.data.rows
						console.log(list);
						this.dataList = this.dataList.concat(list)
						console.log(this.dataList);
					}, (e) => {
						this.$refs.uToast.show({
							title: e,
							type: "error",
							duration: 3000,
						});
					}
				)
			},
			godetail(item) {
				uni.navigateTo({
					url: '/pages/logFollowList/followDetail?id='+item.id,
				})
			},
			editCostomer(item){
				uni.setStorageSync('dotItem',item)
				if(item.status==0){
					uni.navigateTo({
						url: './addFollow?id='+item.id
					})
				}else if(item.status==1){
					uni.navigateTo({
						url: './followDetail?id='+item.id
					})
				}
				
			},
			newAdd() {
				uni.setStorageSync('dotItem', '')
				uni.setStorageSync('logItem', '')
				uni.navigateTo({
					url: './addFollow'
				})
			},
			tabSearch(index, item) {
				this.dataList = []
				this.pageNum=1
				this.pageSize=10
				this.tabIndex = index
				this.status = item.value
				
				this.getList()
			},
			callPhone(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.p20 {
		padding: 20rpx;
	}

	.container-warp {
		box-sizing: border-box;
		width: 100vw;
		min-height: 100vh;
		background-color: #F3F5F7;

		.search-box {
			width: 100%;
			height: 80rpx;
			background-color: #fff;
			border-radius: 40rpx;
			display: flex;
			align-items: center;
			padding: 0 20rpx;
			box-sizing: border-box;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 20rpx;
			}
		}

		.search-tab {
			width: 100%;
			height: 100rpx;
			background: #fff;
			display: flex;
			align-items: center;
			justify-content: space-around;
			// font-size: 30rpx;
			color: #666;

			.tab-item {
				text-align: center;
				// width: 170rpx;
			}

			.search-tab-line {
				width: 30rpx;
				height: 5rpx;
				border-radius: 3rpx;
				background-color: #fff;
				margin: 0 auto;
				margin-top: 10rpx;
			}

			.active {
				color: #007AFF;
				font-weight: 600;
			}

			.lineActive {
				background: #007AFF;
			}
		}

		.scroll-list {
			width: 100%;
			height: calc(100vh - 446rpx);

			// background-color: #ccc;
			.p30 {
				padding: 0 30rpx;
			}

			.list-item {
				position: relative;
				width: 100%;
				padding: 30rpx 0;
				background-color: #fff;
				border-radius: 16rpx;
				margin-top: 20rpx;

				.list-line {
					width: 100%;
					height: 1px;
					background-color: #F7F7F7;
					margin-top: 27rpx;
				}

				.header-box {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.title-box {
						display: flex;
						align-items: center;

						image {
							width: 60rpx;
							height: 60rpx;
							border-radius: 50%;
						}

						.title-name {
							font-size: 32rpx;
							font-weight: 600;
							color: #000;
						}
					}

					.list-state {
						color: #007AFF;
						font-weight: 600;
						display: flex;
						align-items: center;

						.state1 {
							color: #1DC883;
						}

						.state-line {
							color: #D9D9D9;
						}

						.state2 {
							color: #FA8C16;
						}

					}
				}

				.content-box {
					margin-top: 30rpx;

					.info-item {
						font-size: 30rpx;
						color: #999;
						display: flex;
						// align-items: center;
					}

					.info-label {
						width: 140rpx;
						display: inline-block;
						text-align-last: justify;
					}

					.call-icon {
						width: 36rpx;
						height: 36rpx;
						display: inline-block;
						margin-left: 20rpx;
					}

					.info-value {
						flex: 1;
						color: #333;
					}
				}
			}

			.look-log-wrap {
				display: flex;
				justify-content: flex-end;
			}

			.look-log {
				width: 165rpx;
				height: 66rpx;
				background-color: #1DC883;
				border-radius: 36rpx;
				display: flex;
				align-items: center;
				color: #fff;
				font-size: 30rpx;
				justify-content: center;

			}
		}

		.add-btn-wrap {
			width: 100%;
			height: 130rpx;
			background-color: #fff;
			padding-top: 15rpx;

			.add-btn {
				width: 690rpx;
				height: 90rpx;
				border-radius: 54rpx;
				background-color: #307DCD;
				color: #fff;
				display: flex;
				justify-content: center;
				align-items: center;
				margin: 0 auto;

			}
		}
	}

	/deep/.u-checkbox__icon-wrap {
		border: 1px solid #007AFF;
		background-color: #fff;
	}
</style>